/**
 * Created by hps on 17-4-27.
 */
public class StackX1 {
    private int maxSize;
    private char[] stackArray;
    private int top;

    public StackX1(int max) {
        maxSize = max;
        stackArray = new char[maxSize];
        top = -1;
    }

    public boolean push(char c) {
        if(top == maxSize - 1)
            return false;
        stackArray[++top] = c;
        return true;
    }

    public char pop() {
        return stackArray[top--];
    }

    public char peek() {
        return stackArray[top];
    }

    public boolean isEmpty() {
        return top == -1;
    }

    public boolean isFull() {
        return (top == maxSize - 1);
    }

    public int size() {
        return top+1;
    }

    public char peekN(int n) {
        return stackArray[n];
    }

    public void displayStack(String s) {
        System.out.print(s);
        System.out.print(" Stack(bottom-->top): ");
        for(int j = 0; j < size(); j++) {
            System.out.print(peekN(j) + " ");
        }
        System.out.println();
    }
}

